﻿using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using PefStudio.StartUp;

namespace PefStudio.Windows
{
    class AbstractToolStrip : ToolStrip, IToolStrip, IPartImportsSatisfiedNotification
    {
        [Import(Bootstrapper.MainWindowContract, typeof(Form))]
        private Lazy<MainWindow> mainWindow { get; set; }
        protected MainWindow MainWindow
        {
            get { return mainWindow.Value; }
        }

        public string ID { get; set; }
        public double Index { get; set; }
        public string InsertRelativeToID { get; set; }
        public bool BeforeRelativeID { get; set; }

        public virtual void ConditionEvaluate()
        {
            if (Visible == true)
            {
                foreach (var item in Items)
                {
                    var iItem = item as IToolStripItem;
                    if (iItem != null) iItem.ConditionEvaluate();
                }
            }
        }

        public virtual void OnImportsSatisfied()
        {
        }
    }

    class AbstractToolStripButton : ToolStripButton, IToolStripItem
    {
        [Import(Bootstrapper.MainWindowContract, typeof(Form))]
        private Lazy<MainWindow> mainWindow { get; set; }
        protected MainWindow MainWindow
        {
            get { return mainWindow.Value; }
        }

        public string ID { get; set; }
        public double Index { get; set; }
        public string InsertRelativeToID { get; set; }
        public bool BeforeRelativeID { get; set; }

        public virtual void ConditionEvaluate() { }

        public bool HasSeparator { get; set; }
        public ToolStripSeparator ToolStripSeparator { get; set; }

        private Form _parentForm = null;
        public Form ParentForm
        {
            get {
                return _parentForm ?? MainWindow;
            }
            set { _parentForm = value; }
        }
    }

    class AbstractToolStripLable : ToolStripLabel, IToolStripItem
    {
        [Import(Bootstrapper.MainWindowContract, typeof(Form))]
        private Lazy<MainWindow> mainWindow { get; set; }
        protected MainWindow MainWindow
        {
            get { return mainWindow.Value; }
        }

        public string ID { get; set; }
        public double Index { get; set; }
        public string InsertRelativeToID { get; set; }
        public bool BeforeRelativeID { get; set; }

        public virtual void ConditionEvaluate() { }

        public bool HasSeparator { get; set; }
        public ToolStripSeparator ToolStripSeparator { get; set; }

        private Form _parentForm = null;
        public Form ParentForm
        {
            get
            {
                return _parentForm ?? MainWindow;
            }
            set { _parentForm = value; }
        }
    }

    class AbstractToolStripDropDownButton : ToolStripDropDownButton, IToolStripItem
    {
        [Import(Bootstrapper.MainWindowContract, typeof(Form))]
        private Lazy<MainWindow> mainWindow { get; set; }
        protected MainWindow MainWindow
        {
            get { return mainWindow.Value; }
        }

        public string ID { get; set; }
        public double Index { get; set; }
        public string InsertRelativeToID { get; set; }
        public bool BeforeRelativeID { get; set; }

        public virtual void ConditionEvaluate() { }

        public bool HasSeparator { get; set; }
        public ToolStripSeparator ToolStripSeparator { get; set; }

        private Form _parentForm = null;
        public Form ParentForm
        {
            get
            {
                return _parentForm ?? MainWindow;
            }
            set { _parentForm = value; }
        }
    }

    class AbstractToolStripSplitButton : ToolStripSplitButton, IToolStripItem
    {
        [Import(Bootstrapper.MainWindowContract, typeof(Form))]
        private Lazy<MainWindow> mainWindow { get; set; }
        protected MainWindow MainWindow
        {
            get { return mainWindow.Value; }
        }

        public string ID { get; set; }
        public double Index { get; set; }
        public string InsertRelativeToID { get; set; }
        public bool BeforeRelativeID { get; set; }

        public virtual void ConditionEvaluate() { }

        public bool HasSeparator { get; set; }
        public ToolStripSeparator ToolStripSeparator { get; set; }

        private Form _parentForm = null;
        public Form ParentForm
        {
            get
            {
                return _parentForm ?? MainWindow;
            }
            set { _parentForm = value; }
        }
    }

    class AbstractToolStripComboBox : ToolStripComboBox, IToolStripItem
    {
        [Import(Bootstrapper.MainWindowContract, typeof(Form))]
        private Lazy<MainWindow> mainWindow { get; set; }
        protected MainWindow MainWindow
        {
            get { return mainWindow.Value; }
        }

        public string ID { get; set; }
        public double Index { get; set; }
        public string InsertRelativeToID { get; set; }
        public bool BeforeRelativeID { get; set; }

        public virtual void ConditionEvaluate() { }

        public bool HasSeparator { get; set; }
        public ToolStripSeparator ToolStripSeparator { get; set; }

        private Form _parentForm = null;
        public Form ParentForm
        {
            get
            {
                return _parentForm ?? MainWindow;
            }
            set { _parentForm = value; }
        }
    }

    class AbstractToolStripProgressBar : ToolStripProgressBar, IToolStripItem
    {
        [Import(Bootstrapper.MainWindowContract, typeof(Form))]
        private Lazy<MainWindow> mainWindow { get; set; }
        protected MainWindow MainWindow
        {
            get { return mainWindow.Value; }
        }

        public string ID { get; set; }
        public double Index { get; set; }
        public string InsertRelativeToID { get; set; }
        public bool BeforeRelativeID { get; set; }

        public virtual void ConditionEvaluate() { }

        public bool HasSeparator { get; set; }
        public ToolStripSeparator ToolStripSeparator { get; set; }

        private Form _parentForm = null;
        public Form ParentForm
        {
            get
            {
                return _parentForm ?? MainWindow;
            }
            set { _parentForm = value; }
        }
    }
}
